package com.zb.store.controller;


import com.zb.result.PageUtil;
import com.zb.result.Result;
import com.zb.service.ZjStoreTypeService;
import com.zb.utils.TokenUtil;
import com.zb.vo.StoreTypeListSelectVo;
import com.zb.vo.StoreTypeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 仓储类型表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2024-01-06
 */
@Api(tags = "仓库类型类接口")
@RestController
@RequestMapping("/store/type")
public class ZjStoreTypeController {
    @Resource
    private ZjStoreTypeService storeTypeService;

    @ApiOperation("新增或修改仓库类型")
    @PostMapping("/save")
    public Result save(HttpServletRequest request, @RequestBody @Valid StoreTypeVo storeTypeVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        storeTypeService.save(custAccId, storeTypeVo);
        return Result.success(null == storeTypeVo.getId()? "新增仓库类型成功" : "修改仓库类型成功");
    }

    @ApiOperation("获取仓库类型列表")
    @PostMapping("/getList")
    public Result getList(HttpServletRequest request, @RequestBody @Valid StoreTypeListSelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取仓库类型列表成功").data(storeTypeService.getList(custAccId, selectVo));
    }

    @ApiOperation("根据仓库类型ID获取详情")
    @GetMapping("/getDetail/{id}")
    public Result getDetail(@PathVariable @ApiParam(value = "仓库类型ID", required = true) Long id) {
        return Result.success("获取仓库类型详情成功").data(PageUtil.row(storeTypeService.getDetail(id)));
    }

    @ApiOperation("批量启用或禁用仓库类型")
    @PutMapping("/disable")
    public Result disable(@RequestParam @ApiParam(value = "仓库类型状态：false-启用，true-禁用", example = "false") Boolean status,
                          @RequestBody @ApiParam(value = "仓库类型ID", required = true) List<Long> ids) {
        storeTypeService.updateDisableBatchById(ids, status);
        return Result.success(status? "启用仓库类型成功" : "禁用仓库类型成功");
    }

    @ApiOperation("批量删除仓库类型")
    @DeleteMapping("/delete")
    public Result delete(@RequestBody @ApiParam(value = "仓库类型ID", required = true) List<Long> ids) {
        storeTypeService.deleteBatchById(ids);
        return Result.success("删除仓库类型成功");
    }

}
